package top.lishuoboy.hibernate.validator.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import top.lishuoboy.hibernate.validator.mapper.SysUserMapper;
import top.lishuoboy.hibernate.validator.model.SysUser;
import top.lishuoboy.hibernate.validator.service.SysUserService;
import top.lishuoboy.hibernate.validator.service.common.ValidatorService;
import top.lishuoboy.hibernate.validator.validate.group.Insert;
import top.lishuoboy.hibernate.validator.validate.group.UpdateById;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import javax.validation.groups.Default;

/**
 * @author lishuoboy
 * @description 针对表【sys_user(用户)】的数据库操作Service实现
 * @createDate 2024-10-24 14:00:37
 */
@RequiredArgsConstructor
@Service
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser>
    implements SysUserService {

    private final ValidatorService validatorService;

    @Override
    public SysUser save2(SysUser sysUser) {
        validatorService.validate(sysUser, Insert.class, Default.class);
        save(sysUser);
        return sysUser;
    }

    @Override
    public SysUser updateById2(SysUser sysUser) {
        validatorService.validate(sysUser, UpdateById.class, Default.class);
        updateById(sysUser);
        return sysUser;
    }

    @Override
    public SysUser getById2(@NotNull @Min(0) Integer id) {
        return getById(id);
    }
}




